<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>父子组件间的数据传递</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        <counter :count="3" @change="handleIncrease"></counter>
        <counter :count="2" @change="handleIncrease"></counter>
        <div>{{total}}</div>
    </div>

    <script>
        var counter = {
            props: ['count'],
            data: function() {
                return {
                    number: this.count
                }
            },
            template: '<div @click="handleClick">{{number}}</div>',
            methods: {
                handleClick: function() {
                    this.number ++;
                    this.$emit('change', 1);
                }
            },
        }
        var vm = new Vue({
            el: '#app',
            data: {
                total: 5
            },
            components: {
                counter: counter
            },
            methods:{
                handleIncrease: function(value) {
                    this.total += value;
                }
            }
            
        })
    </script>
</body>
</html>